<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>方形网格密度</title>
  <script include="jquery" src="./static/libs/include-lib-local.js"></script>
  <script include="language,proj4,mapv" src="./static/libs/include-mapboxgl-local.js"></script>
  <link href="./static/demo/mapboxgl/example/style.css" rel="stylesheet" type="text/css" />
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    #map {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 100%;
    }
  </style>
</head>

<body>
  <div id="map">
    <div id="mouse-position">
    </div>
  </div>
  <script>
    //一定要去mapbox注册一个key,这个key会失效的
    mapboxgl.accessToken = 'pk.eyJ1IjoicGFybmRlZWRsaXQiLCJhIjoiY2o1MjBtYTRuMDhpaTMzbXhpdjd3YzhjdCJ9.sCoubaHF9-nhGTA-sgz0sA';
    var map = new mapboxgl.Map({
      container: 'map', // 绑定div
      style: 'mapbox://styles/mapbox/dark-v9', // 使用MapBox官方的样式
      center: [115.321317, 30.398428],
      zoom: 3
    });

    map.addControl(new MapboxLanguage(), 'top-right');//中文支持
    map.addControl(new mapboxgl.NavigationControl(), 'top-left');
    //注册鼠标移动事件
    map.on('mousemove', function (e) {
      //经纬度坐标转web墨卡托
      const earthRad = 6378137.0;
      const x = e.lngLat.lng * Math.PI / 180 * earthRad;
      const a = e.lngLat.lat * Math.PI / 180;
      const y = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
      document.getElementById('mouse-position').innerHTML = "X轴：" + x.toFixed(2) + "，Y轴：" + y.toFixed(2);
    });
    var randomCount = 500;
    var data = [];
    while (randomCount--) {
      data.push({
        geometry: {
          type: 'Point',
          coordinates: [75 + Math.random() * 50, 20.3 + Math.random() * 20]
        },
        count: 30 * Math.random()
      });
    }

    var dataSet = new mapv.DataSet(data);

    var options = {
      context: '2d',
      fillStyle: 'rgba(55, 50, 250, 0.8)',
      size: 40,
      globalAlpha: 0.5,
      label: {
        show: true,
        fillStyle: 'white',
        shadowColor: 'yellow',
        font: '15px Arial',
        shadowBlur: 10
      },
      gradient: {
        0: "rgba(49, 54, 149, 0)",
        0.2: "rgba(69,117,180, 0.7)",
        0.3: "rgba(116,173,209, 0.7)",
        0.4: "rgba(171,217,233, 0.7)",
        0.5: "rgba(224,243,248, 0.7)",
        0.6: "rgba(254,224,144,0.7)",
        0.7: "rgba(253,174,97,0.7)",
        0.8: "rgba(244,109,67,0.8)",
        0.9: "rgba(215,48,39,0.8)",
        0.95: "rgba(165, 0, 38,0.8)"
      },
      shadowColor: 'rgba(255, 255, 50, 1)',
      shadowBlur: 10,
      max: 100,
      draw: 'grid'
    }
    var mapvLayer = new mapboxgl.zondy.MapvLayer(map, dataSet, options);
  </script>


</body>

</html>